package com.jinzhi.jinzhidata.controller;

import com.jinzhi.jinzhidata.vo.ResultVO;
import com.jinzhi.jinzhidata.enums.ResultEnum;
import com.jinzhi.jinzhidata.util.ResultVOUtil;
import com.jinzhi.jinzhidata.util.UUIDUtil;
import com.jinzhi.jinzhidata.util.WXHelper;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/share")
public class ShareController {

    @GetMapping(value = "/getShareConfig")
    public ResultVO getShareConfig(@RequestParam String url) {
        if (StringUtils.isEmpty(url)) {
            return ResultVOUtil.error(ResultEnum.NULL_ERROR.getCode(), "分享失败");
        }
        String jsApiTicket = WXHelper.getJsApiTicket();
        String nonceStr = UUIDUtil.getUUID();
        String timestamp = Long.toString(System.currentTimeMillis() / 1000);
        Map<String, String> config = WXHelper.getJsApiConfig(url, jsApiTicket, nonceStr, timestamp);
        return ResultVOUtil.success(config);
    }
}
